<template>
	<view class="flex-col homepage">
		<u-form-item class="formItemInput" label="房屋" :label-width="70">
			<u-input placeholder="请选择您要授权的房屋地址" v-model="form.middleId" type="text" readonly="readonly"></u-input>
		</u-form-item>
		<u-form-item class="formItemInput" label="访客姓名" :label-width="70">
			<u-input placeholder="请输入真实姓名" v-model="form.visitorsName" type="text"></u-input>
		</u-form-item>
		<u-form-item class="formItemActionSheet" label="访客性别" :label-width="70">
			<uni-data-select v-model="form.visitorsAge" :localdata="range" @change="change"></uni-data-select>
		</u-form-item>
		<u-form-item class="formItemInput-two" label="手机号码" :label-width="70">
			<u-input placeholder="请输入手机号码" v-model="form.visitorsPhone" type="text"></u-input>
		</u-form-item>
		<u-form-item class="formItemInput-two" label="访问日期" :label-width="70">
			<view class="example-body">
				<uni-datetime-picker type="datetime" :clear-icon="false" v-model="form.accessTime"
					@maskClick="maskClick" />
			</view>
		</u-form-item>
		<u-form-item class="formItemInput-two" label="访问时长" :label-width="70">
			<u-input placeholder="请选择访问时长" v-model="form.duration" type="text"></u-input>
		</u-form-item>
		<view class="flex-row wrapper">
			<view class="u-line-1 text">是否驱车</view>
			<u-switch v-model="tttt" @change="ttttq()"></u-switch>
		</view>
		<u-form-item class="formItemInput" label="访问车牌号" :label-width="80" v-if="this.carNumber">
			<u-input placeholder="请输入车牌号" v-model="form.visitorsLicencePlate" type="text"></u-input>
		</u-form-item>
		<u-button type="primary" text="生成通行证" @click="Generatepass()" style="width: 380px;"></u-button>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				user:{},
				middleId:'',
				carNumber: false,
				tttt: false,
				single: '',
				sc: '',
				range: [{
						value: 1,
						text: "男"
					},
					{
						value: 2,
						text: "女"
					}
				],
				form: {
					middleId: "",
					visitorsName: "",
					visitorsAge: "",
					visitorsPhone: "",
					accessTime: "",
					duration: "",
					drive: "",
					visitorsLicencePlate: "",
				}
			}
			
		},
		onLoad() {
			// 获取到用户的默认房屋
			this.WjxFindDeaultState();
		},
		methods: {
			// 页面跳转方法
			ttttq() {
				if (this.tttt == true) {
					this.carNumber = true
				} else {
					this.carNumber = false
				}
			},
			change(text) {
			},
			xzrq() {
				this.show = true
			},
			cancel() {
				this.show = false
			},
			//后台方法
			Generatepass() {
				// 为true则代表驱车
				if (this.form.visitorsAge == 1) {
					this.form.visitorsAge = '男'
				} else if (this.form.visitorsAge == 2) {
					this.form.visitorsAge = '女'
				}
				if (this.tttt == true) {
					this.form.drive = '是'
				} else if (this.tttt == false) {
					this.form.drive = '否'
					this.form.visitorsLicencePlate = ''
				}
				this.form.middleId=this.middleId
				this.$axios({
					url: 'serverwg/WjxAddVisitorsRecord',
					data: this.form,
					method: 'POST',
					success: (res) => {
						console.log(res.data.data.visitorsRecord)
						uni.navigateTo({
							url: '../wjx/GeneratedPass',
							success: function(res) {
								uni.navigateTo({
									url: '../wjx/GeneratedPass?data=' +encodeURIComponent(JSON.stringify(res.data.data.visitorsRecord)),
									success: function(res) {
										// console.log(res)
									}
								})
							}
						})

					}
				})
			},
			WjxFindDeaultState(){
				this.user=uni.getStorageSync("user")
				this.$axios({
					url: 'serverwg/WjxFindDeaultState',
					data: {userId:this.user.userId},
					method: 'GET',
					success: (res) => {
						// alert(res.data.data.address)
						// alert(res.data.data.middleId)
						this.form.middleId=res.data.data.address
						this.middleId=res.data.data.middleId
					}
				})
			}


		}
	}
</script>
<style lang="scss" scoped>
	/** 全局样式-开始,建议放在公共css样式文件中,比如common.css 或app.vue文件 */

	html,
	body {
		margin: 0;
		width: 100%;
		height: 100%;
		font-size: 16px
	}

	view,
	text,
	image {
		position: relative;
		box-sizing: border-box;
		flex-shrink: 0;
	}

	.flex-col {
		display: flex;
		align-items: flex-start;
		flex-direction: column;
	}

	.flex-row {
		display: flex;
		align-items: flex-start;
	}

	.flex-col .flex-row {
		width: 100%
	}

	/** 全局样式-结束*/

	.homepage {
		height: 1623.188rpx;
		padding: 28.986rpx 0rpx 0rpx 1.812rpx;
		border-color: #ff9900;

		.formItemInput {
			width: 100%;
		}

		.formItemActionSheet {
			width: 100%;
		}

		.formItemInput-two {
			width: 100%;
			margin-bottom: 12.681rpx;
		}

		.wrapper {
			width: 262.681rpx;
			justify-content: space-between;
			margin-bottom: 21.739rpx;

			.text {
				width: 114.13rpx;
				margin-top: 14.493rpx;
			}
		}
	}
</style>
